<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Overview - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.log.overview.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.log.overview.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.log.html">Zend_Log</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.log.html">Zend_Log</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.log.writers.html">Writers</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.log.overview" class="section"><div class="info"><h1 class="title">Overview</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Log</span> is a component for general purpose logging.
        It supports multiple log backends, formatting messages sent to the log,
        and filtering messages from being logged. These functions are divided
        into the following objects:

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    A Log (instance of <span class="classname">Zend_Log</span>) is the object that your
                    application uses the most. You can have as many Log objects as you
                    like; they do not interact. A Log object must contain at
                    least one Writer, and can optionally contain one or more Filters.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    A Writer (inherits from <span class="classname">Zend_Log_Writer_Abstract</span>) is
                    responsible for saving data to storage.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    A Filter (implements <span class="classname">Zend_Log_Filter_Interface</span>)
                    blocks log data from being saved. A filter may be applied to an
                    individual Writer, or to a Log where it is applied before all
                    Writers. In either case, filters may be chained.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    A Formatter (implements <span class="classname">Zend_Log_Formatter_Interface</span>)
                    can format the log data before it is written by a Writer. Each
                    Writer has exactly one Formatter.
                </p>
            </li>
        </ul>
    </p>

    <div class="section" id="zend.log.overview.creating-a-logger"><div class="info"><h1 class="title">Creating a Log</h1></div>
        

        <p class="para">
            To get started logging, instantiate a Writer and then pass it to a Log instance:
        </p>

        <pre class="programlisting brush: php">
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(&#039;php://output&#039;);

$logger-&gt;addWriter($writer);
</pre>


        <p class="para">
            It is important to note that the Log must
            have at least one Writer. You can add any number of Writers using the
            Log&#039;s  <span class="methodname">addWriter()</span> method.
        </p>

        <p class="para">
            Alternatively, you can pass a Writer directly to constructor of Log as
            a shortcut:
        </p>

        <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_Stream(&#039;php://output&#039;);
$logger = new Zend_Log($writer);
</pre>


        <p class="para">
            The Log is now ready to use.
        </p>
    </div>

    <div class="section" id="zend.log.overview.logging-messages"><div class="info"><h1 class="title">Logging Messages</h1></div>
        

        <p class="para">
            To log a message, call the  <span class="methodname">log()</span> method of a Log instance
            and pass it the message with a corresponding priority:
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;log(&#039;Informational message&#039;, Zend_Log::INFO);
</pre>


        <p class="para">
            The first parameter of the  <span class="methodname">log()</span> method is a string
            <span class="property">message</span> and the second parameter is an integer
            <span class="property">priority</span>. The priority must be one of the priorities recognized by
            the Log instance. This is explained in the next section.
        </p>

        <p class="para">
            A shortcut is also available. Instead of calling the  <span class="methodname">log()</span>
            method, you can call a method by the same name as the priority:
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;log(&#039;Informational message&#039;, Zend_Log::INFO);
$logger-&gt;info(&#039;Informational message&#039;);

$logger-&gt;log(&#039;Emergency message&#039;, Zend_Log::EMERG);
$logger-&gt;emerg(&#039;Emergency message&#039;);
</pre>

    </div>

    <div class="section" id="zend.log.overview.destroying-a-logger"><div class="info"><h1 class="title">Destroying a Log</h1></div>
        

        <p class="para">
            If the Log object is no longer needed, set the variable containing it to
            <b><tt>NULL</tt></b> to destroy it. This will automatically call the
             <span class="methodname">shutdown()</span> instance method of each attached Writer before
            the Log object is destroyed:
        </p>

        <pre class="programlisting brush: php">
$logger = null;
</pre>


        <p class="para">
            Explicitly destroying the log in this way is optional and is performed
            automatically at <acronym class="acronym">PHP</acronym> shutdown.
        </p>
    </div>

    <div class="section" id="zend.log.overview.builtin-priorities"><div class="info"><h1 class="title">Using Built-in Priorities</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Log</span> class defines the following priorities:
        </p>

        <pre class="programlisting brush: php">
EMERG   = 0;  // Emergency: system is unusable
ALERT   = 1;  // Alert: action must be taken immediately
CRIT    = 2;  // Critical: critical conditions
ERR     = 3;  // Error: error conditions
WARN    = 4;  // Warning: warning conditions
NOTICE  = 5;  // Notice: normal but significant condition
INFO    = 6;  // Informational: informational messages
DEBUG   = 7;  // Debug: debug messages
</pre>


        <p class="para">
            These priorities are always available, and a convenience method of the same name
            is available for each one.
        </p>

        <p class="para">
            The priorities are not arbitrary. They come from the BSD syslog protocol,
            which is described in <a href="http://tools.ietf.org/html/rfc3164" class="link external">&raquo; RFC-3164</a>.
            The names and corresponding priority numbers are also
            compatible with another <acronym class="acronym">PHP</acronym> logging system,
            <a href="http://pear.php.net/package/log" class="link external">&raquo; PEAR Log</a>,
            which perhaps promotes interoperability between it and <span class="classname">Zend_Log</span>.
        </p>

        <p class="para">
            Priority numbers descend in order of importance. <b><tt>EMERG</tt></b> (0)
            is the most important priority. <b><tt>DEBUG</tt></b> (7) is the least
            important priority of the built-in priorities. You may define priorities
            of lower importance than <b><tt>DEBUG</tt></b>. When
            selecting the priority for your log message, be aware of this priority
            hierarchy and choose appropriately.
        </p>
    </div>

    <div class="section" id="zend.log.overview.user-defined-priorities"><div class="info"><h1 class="title">Adding User-defined Priorities</h1></div>
        

        <p class="para">
            User-defined priorities can be added at runtime using the Log&#039;s
             <span class="methodname">addPriority()</span> method:
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;addPriority(&#039;FOO&#039;, 8);
</pre>


        <p class="para">
            The snippet above creates a new priority, <b><tt>FOO</tt></b>, whose
            value is &#039;8&#039;. The new priority is then available for logging:
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;log(&#039;Foo message&#039;, 8);
$logger-&gt;foo(&#039;Foo Message&#039;);
</pre>


        <p class="para">
            New priorities cannot overwrite existing ones.
        </p>
    </div>

    <div class="section" id="zend.log.overview.understanding-fields"><div class="info"><h1 class="title">Understanding Log Events</h1></div>
        

        <p class="para">
            When you call the  <span class="methodname">log()</span> method or one of its shortcuts, a
            log event is created. This is simply an associative array with data
            describing the event that is passed to the writers. The following keys
            are always created in this array: <span class="property">timestamp</span>,
            <span class="property">message</span>, <span class="property">priority</span>, and
            <span class="property">priorityName</span>.
        </p>

        <p class="para">
            The creation of the <span class="property">event</span> array is completely transparent.
            However, knowledge of the <span class="property">event</span> array is required for adding an
            item that does not exist in the default set above.
        </p>

        <p class="para">
            To add a new item to every future event, call the
             <span class="methodname">setEventItem()</span> method giving a key and a value:
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;setEventItem(&#039;pid&#039;, getmypid());
</pre>


        <p class="para">
            The example above sets a new item named <span class="property">pid</span> and populates
            it with the PID of the current process. Once a new item has been
            set, it is available automatically to all writers along with all of the
            other data event data during logging. An item can be overwritten at any
            time by calling the  <span class="methodname">setEventItem()</span> method again.
        </p>

        <p class="para">
            Setting a new event item with  <span class="methodname">setEventItem()</span> causes the
            new item to be sent to all writers of the logger. However, this does
            not guarantee that the writers actually record the item. This is
            because the writers won&#039;t know what to do with it unless a formatter
            object is informed of the new item. Please see the section on Formatters
            to learn more.
        </p>
    </div>

    <div class="section" id="zend.log.overview.as-errorHandler"><div class="info"><h1 class="title">Log PHP Errors</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Log</span> can also be used to log <acronym class="acronym">PHP</acronym> errors.
            Calling  <span class="methodname">registerErrorHandler()</span> will add
            <span class="classname">Zend_Log</span> before the current error handler, and will pass the
            error along as well.
        </p>

        <table id="zend.log.overview.as-errorHandler.properties.table-1" class="doctable table"><div class="info"><caption><b>
                Zend_Log events from PHP errors have the additional fields matching
                 <span class="methodname">handler  ( int $errno  , string $errstr  [, string $errfile  [, int
                    $errline  [, array $errcontext  ]]] )</span> from <a href="http://us3.php.net/manual/en/function.set-error-handler.php" class="link external">&raquo; set_error_handler</a>
            </b></caption></div>
            

            
                <thead valign="middle">
                    <tr valign="middle">
                        <th>Name</th>
                        <th>Error Handler Parameter</th>
                        <th>Description</th>
                    </tr>

                </thead>


                <tbody valign="middle" class="tbody">
                    <tr valign="middle">
                        <td align="left">message</td>
                        <td align="left">errstr</td>
                        <td align="left">Contains the error message, as a string.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">errno</td>
                        <td align="left">errno</td>
                        <td align="left">Contains the level of the error raised, as an integer.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">file</td>
                        <td align="left">errfile</td>

                        <td align="left">
                            Contains the filename that the error was raised in, as a string.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">line</td>
                        <td align="left">errline</td>

                        <td align="left">
                            Contains the line number the error was raised at, as an integer.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left">context</td>
                        <td align="left">errcontext</td>

                        <td align="left">
                            (optional) An array that points to the active symbol table at the point
                            the error occurred. In other words, errcontext  will contain an array of
                            every variable that existed in the scope the error was triggered in.
                            User error handler must not modify error context.
                        </td>
                    </tr>


                </tbody>
            
        </table>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.log.html">Zend_Log</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.log.html">Zend_Log</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.log.writers.html">Writers</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.log.html">Zend_Log</a></li>
  <li class="active"><a href="zend.log.overview.html">Overview</a></li>
  <li><a href="zend.log.writers.html">Writers</a></li>
  <li><a href="zend.log.formatters.html">Formatters</a></li>
  <li><a href="zend.log.filters.html">Filters</a></li>
  <li><a href="zend.log.factory.html">Using the Factory to Create a Log</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>